function verify(message, options){
  this.message = message;
  this.options = options || {};
  this.null = (rule, value, callback) => {
    if(value === null || value === ''){
      return callback(new Error(this.message));
    }
    return callback();
  };
  this.preNull = (rule, value, callback) => {
    
    if(this.options.pre_val === null || this.options.pre_val === ''){
      return callback(new Error(this.message));
    };
    return callback();
  };
  this.num = (rule, value, callback) => {//function(data, name, min){
    if(value == null || String(value) == '' || Number(value) < this.options.min_number){
      return callback(new Error(this.options.name + '不能为空，且必须是大于或等于'+ this.options.min_number +'的数字！'));
    }
    return callback();
  };
  this.same = (rule, value, callback) => {// function(first_data, second_data, message){
    if(value != this.options.confirm_value){
      return callback(new Error(message));
    }
    return callback();
  };
  this.len = (rule, value, callback) => {
    if(value){
      if(value.trim().length < this.options.length){
        return callback(new Error(this.message));
      }
    }else{
      return callback(new Error(this.message));
    }
    return callback();
  };
  this.email = (rule, value, callback) => {
    let is_email = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(value);
    let msg = this.message || '请填写正确的邮箱！';
    if(!is_email) {
      return callback(new Error(msg));
    }
    return callback();
  };
  this.mobile = (rule, value, callback) => {
    let is_mobile = /^1[0-9]{10}$/.test(value);
    let msg = this.message || '请填写正确的手机号码！';
    if(!is_mobile) {
      return callback(new Error(msg));
    }
    return callback();
  };
  this.phone = (rule, value, callback) => {
    let is_phone = /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(value);
    let msg = this.message || '请填写正确的电话号码！';
    if(!is_phone){
      return callback(new Error(msg));
    }
    return callback();
  };
  this.url = (rule, value, callback) => {
    let is_url = /^http[s]?:\/\/.*/.test(value);
    let msg = this.message || '请填写正确的网络地址！';
    if(!is_url){
      return callback(new Error(msg));
    }
    return callback();
  };
  // 校验 请输入中文、英文、数字包括下划线
  this.nameCn = (rule, value, callback) => {
    let acount = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/
    if (value && (!(acount).test(value))) {
      callback(new Error('请输入中文、英文、数字包括下划线'))
    } else {
      callback()
    }
  };
  //校验 请输入英文、数字包括下划线
  this.nameEn = (rule, value, callback) => {
    let acount = /^[A-Z_]+$/
    if (value && (!(acount).test(value))) {
      callback(new Error('请输入大写英文、下划线'))
    } else {
      callback()
    }
  };
  //校验首尾空白字符的正则表达式
  this.checkSpace = (rule, value, callback) => {
    let longrg = /[^\s]+$/;
    if(!longrg.test(value)){
      callback(new Error('请输入非空格信息'));
    } else {
      callback();
    }
  };
}

export default verify;
 